package com.yzyz.web.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yzyz.utils.Global;

public class AdminInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		if(handler.getClass().getName().indexOf("com.yzyz.management.web.LoginController") != -1) {
			return true;
		}
		if(handler.getClass().getName().indexOf("com.yzyz.management.web") != -1) {
			if(request.getSession().getAttribute(Global.ROLE) == null) {
				response.sendError(HttpServletResponse.SC_FORBIDDEN);
				return false;
			}
		}
		return super.preHandle(request, response, handler);
	}

}
